home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 001 / dotty / dotty.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  5KB  |  172 lines

  1. /*
  2.  * Article 2308 of net.sources:
  3.  * ion: version B 2.10.2 9/17/84 chuqui version 1.9 3/12/85; site unisoft.UUCP
  4.  * Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site amiga.amiga.UUCP
  5.  * Path: unisoft!dual!vecpyr!lll-lcc!lll-crg!seismo!harvard!bbnccv!bbncca!wanginst!decvax!decwrl!pyramid!amiga!dale
  6.  * From: dale@amiga.UUCP (Dale Luck)
  7.  * Newsgroups: net.sources
  8.  * Subject: source to amiga dot graphics demo
  9.  * Message-ID: <137@amiga.amiga.UUCP>
  10.  * Date: 25 Oct 85 01:27:11 GMT
  11.  * Date-Received: 30 Oct 85 05:04:57 GMT
  12.  * References: <1359@ihlpg.UUCP>
  13.  * Reply-To: dale@tooter.UUCP (Dale Luck)
  14.  * Distribution: net
  15.  * Organization: Commodore-Amiga Inc., 983 University Ave #D, Los Gatos CA 95030
  16.  * Lines: 151
  17.  * 
  18.  * For those that are interested, here is a sample program that uses the
  19.  * window libraries and message stuff on the amiga.  If there is going to be
  20.  * significant quantities of shared amiga source maybe we should have an
  21.  * net.sources.amiga
  22.  *     Happy Hacking
  23.  *       Dale
  24.  * 
  25.  */
  26.  
  27. #include <exec/types.h>
  28. #include <exec/nodes.h>
  29. #include <exec/lists.h>
  30. #include <exec/ports.h>
  31. #include <graphics/gfx.h>
  32. #include <graphics/clip.h>
  33. #include <graphics/view.h>
  34. #include <graphics/rastport.h>
  35. #include <graphics/layers.h>
  36. #include <intuition/intuition.h>
  37.  
  38. struct IntuitionBase *IntuitionBase;
  39. struct GfxBase *GfxBase;
  40.  
  41. #define DEPTH   2
  42.  
  43. #define WIDTH  100
  44. #define HEIGHT 50
  45.  
  46. int waiting_for_message = FALSE;
  47.  
  48. char dotty[] = "Dotty Window";
  49.  
  50. int usable_width(w)
  51. struct Window *w;
  52. {
  53.    return (w->Width - w->BorderLeft - w->BorderRight);
  54. }
  55.  
  56. int usable_height(w)
  57. struct Window *w;
  58. {
  59.    return(w->Height - w->BorderTop - w->BorderBottom);
  60. }
  61.  
  62. main()
  63. {
  64.    struct RastPort *rp;
  65.    struct Window *window;
  66.    struct NewWindow nw;
  67.    int x,y,c;
  68.    int xoffset,yoffset;
  69.    int width,height;
  70.    struct IntuiMessage *message;
  71.    ULONG MessageClass;
  72.  
  73.    if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",1)))
  74.    {
  75.       printf("no graphics library!!!\n");
  76.       exit(1);
  77.    }
  78.  
  79.    if (!(IntuitionBase = (struct IntuitionBase *)
  80.                            OpenLibrary("intuition.library",1)) )
  81.    {
  82.       CloseLibrary(GfxBase);
  83.       printf("no intuition here!!\n");
  84.       exit(1);
  85.    }
  86.  
  87.    nw.LeftEdge = 50;
  88.    nw.TopEdge = 50;
  89.    nw.Width = WIDTH;
  90.    nw.Height = HEIGHT;
  91.    nw.DetailPen = -1;
  92.    nw.BlockPen = -1;
  93.    nw.IDCMPFlags = CLOSEWINDOW
  94.                  | REFRESHWINDOW
  95.                  | SIZEVERIFY
  96.                  | NEWSIZE;
  97.    nw.Flags = WINDOWDEPTH
  98.             | WINDOWSIZING
  99.             | WINDOWDRAG
  100.             | WINDOWCLOSE
  101.             | SIMPLE_REFRESH;
  102.    nw.FirstGadget = NULL;
  103.    nw.CheckMark = NULL;
  104.    nw.Title = dotty;
  105.    nw.Screen = NULL;
  106.    nw.BitMap = NULL;
  107.  
  108.    nw.MinHeight = 10;
  109.    nw.MinWidth = 10;
  110.    nw.MaxHeight = 200;
  111.    nw.MaxWidth = 640;
  112.  
  113.    nw.Type = WBENCHSCREEN;
  114.  
  115.    if (!(window = (struct Window *)OpenWindow(&nw) ))
  116.    {
  117.       printf("could not open the window\n");
  118.       CloseLibrary(IntuitionBase);
  119.       CloseLibrary(GfxBase);
  120.       exit(2);
  121.    }
  122.    width = usable_width(window);
  123.    height = usable_height(window);
  124.    rp = window->RPort;
  125.    xoffset = window->BorderLeft;
  126.    yoffset = window->BorderTop;
  127.    while (TRUE)      /* do this forever, or until user gets bored */
  128.    {
  129.       while (!(message = (struct IntuiMessage *)GetMsg(window->UserPort)) )
  130.       {
  131.          if (waiting_for_message)   Wait(1<<window->UserPort->mp_SigBit);
  132.          else
  133.          {
  134.             x = RangeRand(width);
  135.             y = RangeRand(height);
  136.             c = RangeRand(32);
  137.             SetAPen(rp,c);
  138.             WritePixel(rp,xoffset+x,yoffset+y);
  139.          }
  140.       }
  141.       MessageClass = message->Class;
  142.       ReplyMsg(message);
  143.       switch (MessageClass)
  144.       {
  145.          case CLOSEWINDOW  :  CloseWindow(window);
  146.                               CloseLibrary(IntuitionBase);
  147.                               CloseLibrary(GfxBase);
  148.                               exit(0);
  149.  
  150.         case SIZEVERIFY   :  waiting_for_message = TRUE;
  151.                              break;
  152.  
  153.         case REFRESHWINDOW:  BeginRefresh(window);
  154.                              SetAPen(rp,0);
  155.                              /* should not have to recalculate these */
  156.                              width = usable_width(window);
  157.                              height = usable_height(window);
  158.                              RectFill(rp,xoffset,yoffset,
  159.                                          xoffset+width-1,yoffset+height-1);
  160.                              EndRefresh(window,TRUE);
  161.                              break;
  162.  
  163.         case NEWSIZE      :  waiting_for_message = FALSE;
  164.                              width = usable_width(window);
  165.                              height = usable_height(window);
  166.                              break;
  167.      }
  168.   }
  169. }
  170.  
  171.  
  172.